//@ts-ignore这里书写属性相关的API文件
import request from '@/utils/request'
//@ts-ignore属性管理模块接口地址
enum API {
    //获取一级分类接口地址
    C1_URL = '/admin/product/getCategory1',
    //获取二级分类接口地址
    C2_URL = '/admin/product/getCategory2/',
    //获取三级分类接口地址
    C3_URL = '/admin/product/getCategory3/',
    //获取分类下已有的属性与属性值
    ATTR_URL = '/admin/product/attrInfoList/',
    //添加或删除已有属性的接口
    ADDORUPDATEATTR_URL = "/admin/product/saveAttrInfo",
    //删除某一个已有的属性
    DELETEATTR_URL = '/admin/product/deleteAttr/',
}

//获取一级分类的接口方法
export const reqC1 = () => request.get<any, any>(API.C1_URL)
//获取二级分类的接口方法
export const reqC2 = (category1Id: string | number | undefined) => {
    return request.get<any, any>(API.C2_URL + category1Id)
}
//获取三级分类的接口方法
export const reqC3 = (category2Id: string | number | undefined) => {
    return request.get<any, any>(API.C3_URL + category2Id)
}

export const reqAttr = (category1Id: string | number | undefined,
                        category2Id: string | number | undefined,
                        category3Id: string | number | undefined,) => {
    // 确保参数不为undefined
    const c1 = category1Id || '';
    const c2 = category2Id || '';
    const c3 = category3Id || '';
    return request.get<any, any>(API.ATTR_URL + `${c1}/${c2}/${c3}`)
}

export const reAddOrUpdateAttr = (data: any) => {
    return request.post<any, any>(API.ADDORUPDATEATTR_URL, data);
}

export const reqRemoveAttr = (attrId: number) => {
    return request.delete<any, any>(API.DELETEATTR_URL + attrId);
}